package com.neiquan.backstage.platform_article.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neiquan.backstage.common.util.ExtraSpringHibernateTemplate;
import com.neiquan.backstage.platform_article.PlatformArticleTypeService;
import com.neiquan.backstage.pub.bsc.dao.po.PlatformArticleType;

@Service
public class PlatformArticleTypeServiceImpl implements PlatformArticleTypeService {
	private static Class<?> poc = PlatformArticleType.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;

	@Override
	public PlatformArticleType queryById(Integer id) {
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "articleTypeId", id);
	}

	@Override
	public boolean exists(String name) {
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "name", name) != null;
	}

	@Override
	public void add(String name) {
		PlatformArticleType entity = new PlatformArticleType();
		entity.setName(name);
		entity.setDtCreat(System.currentTimeMillis());
		extraSpringHibernateTemplate.getHibernateTemplate().save(entity);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<PlatformArticleType> queryAll() {
		return (List<PlatformArticleType>) extraSpringHibernateTemplate.findAll(poc);
	}
}
